import { operateActionType } from '@/types/enum'
import { FormSchema } from '@/components/Form/index'

// 信息查看时input等组件赋值文字显示
export const getUpdateSchemaArr = (schemas: FormSchema[] | undefined, type = operateActionType.VIEW) => {
  let updateSchemaArr: FormSchema[] = []
  ;(schemas as FormSchema[]).forEach((schemasItem: FormSchema) => {
    updateSchemaArr.push({
      field: schemasItem.field,
      component:
        (type === operateActionType.VIEW || type === operateActionType.AUTH) && !schemasItem.slot
          ? 'BasicTxt'
          : schemasItem.component
    })
  })
  return updateSchemaArr
}

// 通过value获取label值
export const getLabelName = (
  arrList: any[],
  inputValue: string | number,
  params = { label: 'label', value: 'value' }
) => {
  let { label, value } = params
  if (Array.isArray(arrList) && arrList.length) {
    for (let i = 0; i < arrList.length; i++) {
      if (arrList[i][value] === inputValue) {
        return arrList[i][label]
      }
    }
  }
  return ''
}
export const getSwitchLabelName = (data: any, inputValue: string | number) => {
  if (data.checkedValue === inputValue) {
    return data.checkedChildren
  } else if (data.unCheckedValue === inputValue) {
    return data.unCheckedChildren
  }
  return ''
}
